package com.edu.exam.entity.examination.paper;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 监考员工作量统计实体类
 * 所属模块：E-01 考试执行模块
 * 对应数据库表：invigilator_workload_statistics
 *
 * <p>监考员工作量统计实体，记录监考员在指定时间段内的工作量统计信息。
 * 支持按不同时间维度进行工作量分析和均衡性评估。</p>
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "invigilator_workload_statistics",
       uniqueConstraints = @UniqueConstraint(columnNames = {"invigilator_id", "period_start_date", "period_end_date"}))
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class InvigilatorWorkloadStatistics {

    /**
     * 统计ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long statisticsId;

    /**
     * 监考员ID
     */
    @Column(name = "invigilator_id", nullable = false)
    private Long invigilatorId;

    /**
     * 监考员姓名
     */
    @Column(name = "invigilator_name", length = 50, nullable = false)
    private String invigilatorName;

    /**
     * 监考员编号
     */
    @Column(name = "invigilator_code", length = 20, nullable = false)
    private String invigilatorCode;

    /**
     * 部门名称
     */
    @Column(name = "department_name", length = 100, nullable = false)
    private String departmentName;

    /**
     * 统计开始日期
     */
    @Column(name = "period_start_date", nullable = false)
    private LocalDate periodStartDate;

    /**
     * 统计结束日期
     */
    @Column(name = "period_end_date", nullable = false)
    private LocalDate periodEndDate;

    /**
     * 统计日期
     */
    @Column(name = "statistics_date", nullable = false)
    private LocalDate statisticsDate;

    /**
     * 统计类型
     */
    @Column(name = "statistics_type", length = 20, nullable = false)
    private String statisticsType;

    /**
     * 安排数量
     */
    @Column(name = "assignment_count", nullable = false)
    private Integer assignmentCount;

    /**
     * 总监考时长（分钟）
     */
    @Column(name = "total_hours", nullable = false)
    private BigDecimal totalHours;

    /**
     * 考试类型数量
     */
    @Column(name = "exam_type_count", nullable = false)
    private Integer examTypeCount;

    /**
     * 考场数量
     */
    @Column(name = "venue_count", nullable = false)
    private Integer venueCount;

    /**
     * 工作量分数
     */
    @Column(name = "workload_score", precision = 10, scale = 2)
    private BigDecimal workloadScore;

    /**
     * 均衡状态
     */
    @Column(name = "balance_status", length = 20)
    private String balanceStatus;

    /**
     * 平均监考时长（分钟）
     */
    @Column(name = "average_duration_minutes")
    private Integer averageDurationMinutes;

    /**
     * 最长监考时长（分钟）
     */
    @Column(name = "max_duration_minutes")
    private Integer maxDurationMinutes;

    /**
     * 最短监考时长（分钟）
     */
    @Column(name = "min_duration_minutes")
    private Integer minDurationMinutes;

    /**
     * 工作日监考数量
     */
    @Column(name = "weekday_assignments")
    private Integer weekdayAssignments;

    /**
     * 周末监考数量
     */
    @Column(name = "weekend_assignments")
    private Integer weekendAssignments;

    /**
     * 夜间监考数量
     */
    @Column(name = "night_assignments")
    private Integer nightAssignments;

    /**
     * 主考官次数
     */
    @Column(name = "chief_invigilator_count")
    private Integer chiefInvigilatorCount;

    /**
     * 副主考官次数
     */
    @Column(name = "vice_chief_count")
    private Integer viceChiefCount;

    /**
     * 总监考费用
     */
    @Column(name = "total_fee", precision = 10, scale = 2)
    private BigDecimal totalFee;

    /**
     * 平均监考费用
     */
    @Column(name = "average_fee", precision = 10, scale = 2)
    private BigDecimal averageFee;

    /**
     * 出勤率
     */
    @Column(name = "attendance_rate", precision = 5, scale = 2)
    private BigDecimal attendanceRate;

    /**
     * 准时率
     */
    @Column(name = "punctuality_rate", precision = 5, scale = 2)
    private BigDecimal punctualityRate;

    /**
     * 工作评价平均分
     */
    @Column(name = "average_performance_score", precision = 5, scale = 2)
    private BigDecimal averagePerformanceScore;

    /**
     * 统计备注
     */
    @Column(name = "statistics_remarks", length = 500)
    private String statisticsRemarks;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    /**
     * 更新时间
     */
    @LastModifiedDate
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

    /**
     * 监考员关联
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "invigilator_id", insertable = false, updatable = false)
    private Invigilator invigilator;
}